package main;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import lombok.SneakyThrows;
import utils.SmallTool;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author 葛成瑞
 * @crete 2021年8月27日15:24:14
 */
public class ReadDbCheckData {

    static String dbName = "xml_content";
    static String insetTable = "pubmed_vip_extend_new";

    // 2021年8月27日15:24:08 用于检测数据是不是正确


    @SneakyThrows
    public static void main(String[] args) {


        String allDate = "select max(pmid) as pmid  from " + dbName;
        Entity query = Db.use().query(allDate).get(0);
        SmallTool.printMess("最大的id 是" + query.getStr("pmid"));

        Integer count = query.getInt("pmid");
        int breakSize = 100000;
        int pageSize = count / breakSize + 1;
        SmallTool.printMess("全部页码+++++++++" + pageSize);

        SmallTool.printMess("任务开始+++++++++++++++++++++++++++++++++++++++++++++++++++++");
        //shuju
        for (int i = 1; i <= pageSize; i++) {
            SmallTool.printMess("当前页码+++++" + i);
            int start = breakSize * (i - 1) + 1;
            int end = i * breakSize;
            SmallTool.printMess("开始id++" + start + "+++结束id++++" + end);
            String paramSql = "select * from " + dbName + " where  pmid between  " + start + " and " + end;
            String ToparamSql = "select pmid from " + insetTable + " where  pmid between  " + start + " and " + end;
            List<Entity> querys = Db.use().query(paramSql);
            List<Entity> querysTo = Db.use().query(ToparamSql);
            Set<Integer> fromIds = querys.stream().map(o -> o.getInt("pmid")).collect(Collectors.toSet());
            Set<Integer> toIds = querysTo.stream().map(o -> o.getInt("pmid")).collect(Collectors.toSet());

            if (fromIds.size() != toIds.size()) {
                List<Integer> collect = fromIds.stream().filter(o -> !toIds.contains(o)).collect(Collectors.toList());
                SmallTool.printMess("不存在的++" + collect);

            }


        }
    }

}
